package com.atguigu.java.ai.langchain4j.config;

import com.atguigu.java.ai.langchain4j.store.MongoChatMemoryStore;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 🐱🐱🐱
 * @Date: 2025/9/1 19:25
 * @Description:
 **/
@Configuration
public class MemoryChatAssistantConfig {
    @Bean
    ChatMemory chatMemory(){
        //设置聊天记忆记录的message数量
        MessageWindowChatMemory windowChatMemory = MessageWindowChatMemory.withMaxMessages(10);
        return windowChatMemory;
    }

    @Resource
    private MongoChatMemoryStore mongoChatMemoryStore;
    @Bean
    ChatMemoryProvider chatMemoryProvider(){
        return MemoryId->
                MessageWindowChatMemory
                        .builder()
                        .id(MemoryId)
                        .maxMessages(10)
                        .chatMemoryStore(mongoChatMemoryStore)
                        .build();
    }
}
